﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using CentralOffice.PublicAffair.Data;
using CentralOffice.PublicAffair.BusinessActions;

using FavoriteTable = CentralOffice.PublicAffair.Data.FavoriteDataSet.FavoriteDataTable;
using FavoriteRow = CentralOffice.PublicAffair.Data.FavoriteDataSet.FavoriteRow;
using System.Data;



namespace CentralOffice.WebClient.PublicAffairs
{
    public partial class FavoriteQuery : PageBase
    {


        private bool? authorized = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                
                if (authorized == null)
                {
                    authorized = this.Authorize(AuthorizationRules.Favorite_Edit);
                }
                if (!authorized.Value)
                {
                    gv.Columns.RemoveAt(gv.Columns.Count - 1);
                }
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            gv.PageIndex = 0;

            FavoriteRow favorite = (new FavoriteDataSet()).Favorite.NewFavoriteRow();


            favorite.Name = txtName.Text;
           
            favorite.Link = txtLink.Text;




            odsFavorite.SelectParameters.Clear();
            odsFavorite.SelectParameters.Add("whereClause", favorite.FilterExpression);
        }

        protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //FavoriteRow favorite = ((DataRowView)e.Row.DataItem).Row as FavoriteRow;

                //if (!favorite.IsNameNull())
                //{
                //    HyperLink link = e.Row.Cells[0].Controls[0] as HyperLink;
                //    link.Text = favorite.Name;
                //    //SiteUtil.GenernateDownloadHyperLink(link, train.Attachments);
                //}

            }
        }
    }
}
